// ProjectName: go-learn-demo
// PackageName: reflectybxb
// Description:
// Author: hy.bai
// Date: 2025-08-14 星期四 16:25

package reflectybxb

import (
	"fmt"
	"reflect"
)

func TestIntReflect() {
	var num int32 = 10
	numVal := reflect.ValueOf(num)
	// numVal.SetInt(100)
	fmt.Println("是否可设置:", numVal.CanSet()) // 是否可设置: false
}

func TestIntReflect1() {
	var num int32 = 10
	numVal := reflect.ValueOf(&num) // &num:获取变量的地址
	// numVal.SetInt(100)
	fmt.Println("是否可设置:", numVal.CanSet()) // 是否可设置: false
}

func TestIntReflect2() {
	var num int32 = 10
	numVal := reflect.ValueOf(&num) // &num:获取变量的地址
	elem := numVal.Elem()
	fmt.Println("是否可设置:", elem.CanSet()) // 是否可设置: false
	elem.SetInt(100)
	fmt.Println("elem:", elem.Interface())
	fmt.Println("num:", num)
}
